package com.thti.mecool.client.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

public class LinearLayoutForListView extends LinearLayout {

    private AdapterForLinearLayout adapter;
    private OnClickListener onClickListener = null;
    private OnLongClickListener longClickListener=null;
    /** 
     * 绑定布局 
     */ 
    public void bindLinearLayout() {
    	int count=0;
        count = adapter.getCount();
        removeAllViews();
        for (int i = 0; i < count; i++) {
            View v = adapter.getView(i, null, null);

            v.setOnClickListener(this.onClickListener);
            v.setOnLongClickListener(this.longClickListener);
            if (i == count - 1) {
                LinearLayout ly = (LinearLayout) v;
                ly.removeViewAt(2);
            }
            addView(v, i);
        }
        Log.v("countTAG", "" + count);
    }

    public OnLongClickListener getLongClickListener() {
		return longClickListener;
	}

	@Override
	public void setOnLongClickListener(OnLongClickListener longClickListener) {
		this.longClickListener = longClickListener;
	}

	public LinearLayoutForListView(Context context) {
        super(context);

    }

    public LinearLayoutForListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub

    }

    /** 
     * 获取Adapter 
     * 
     * @return adapter 
     */  
    public AdapterForLinearLayout getAdpater() {
        return adapter;
    }
    
    /** 
     * 设置数据 
     * 
     * @param adpater 
     */ 
    public void setAdapter(AdapterForLinearLayout adpater1) {
    	if(adapter!=null){
    		adapter=null;
    	}
        this.adapter = adpater1;
        bindLinearLayout();
    }

    /** 
     * 获取点击事件 
     * 
     * @return 
     */  
    public OnClickListener getOnclickListner() {
        return onClickListener;
    }

    /** 
     * 设置点击事件 
     * 
     * @param onClickListener 
     */  
    public void setOnclickLinstener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }
    


}
